import constant from '@/store/constant.js'
import common from '@/store/common.js'
const baseUrl=constant.baseUrl;
const authInfo=constant.authInfo;

export default {
	state:{//存放状态
	
		prizeList:[],
		historyPrizeList:[],
		
		
	},
	mutations: {
		
		loadPrizeData(state,data){
			
		
			state.prizeList=[]
			for(let index in data.data){
				state.prizeList.push(data.data[index])
			}
		
			
		},
		loadHistoryPrizeData(state,data){
			
		
			state.historyPrizeList=[]
			for(let index in data.data){
				state.historyPrizeList.push(data.data[index])
			}
		
			
		},
		
		
	},
	actions:{
		
		loadPrizeData(context,data){
			
			console.log("loadPrizeData"+JSON.stringify(data))
			uni.request({
				url: baseUrl+'/api/prize/listForPage',
				method: 'POST',
				header: {
				        'auth': uni.getStorageSync("token") 
				    },
				data: {"pageNum":data.pageNum,"pageSize":data.pageSize},
				success: (res) => {
					if(res.data.code==0){
					
						context.commit('loadPrizeData',{"data":res.data.result.data})
						
					}else{
						common.dataError(res.data);
						console.log(res.data.message);
					}
			
				},
				fail: (err) => {
					common.jumpToLogin();
					console.log(err);
				}
			})
			
		},
		loadHistoryPrizeData(context,data){
			
			console.log("loadHistoryPrizeData"+JSON.stringify(data))
			uni.request({
				url: baseUrl+'/api/prize/historyListForPage',
				method: 'POST',
				header: {
				        'auth': uni.getStorageSync("token") 
				    },
				data: {"pageNum":data.pageNum,"pageSize":data.pageSize},
				success: (res) => {
					if(res.data.code==0){
						context.commit('loadHistoryPrizeData',{"data":res.data.result.data})
					}else{
						common.dataError(res.data);
						console.log(res.data.message);
					}
			
				},
				fail: (err) => {
					common.jumpToLogin();
					console.log(err);
				}
			})
			
		},
		exchangePrizeData(context,data){
			
			console.log("exchangePrizeData"+JSON.stringify(data))
			uni.request({
				url: baseUrl+'/api/prize/exchangePrize',
				method: 'POST',
				header: {
				        'auth': uni.getStorageSync("token") 
				    },
				data:data,
				success: (res) => {
					if(res.data.code==0){
					
						
					}else{
						common.dataError(res.data);
						console.log(res.data.message);
					}
			
				},
				fail: (err) => {
					common.jumpToLogin();
					console.log(err);
				}
			})
			
		},
		
		
	}
}